package com.njwb.day15.zqzb.ios.io2;

import java.io.*;

public class FileReaderDemo02 {
    public static void main(String[] args) {
        //专门用来处理字符数据的流
        Reader reader = null ;
        File f = new File("e:"+File.separator+"bak.txt");
        try {
            //处理单位就是字符
            reader = new FileReader(f);
            int count = 0 ;
            int length = 0 ;
            char[] buffer  = new char[3] ;
            while((length=reader.read(buffer))!=-1) {
                System.out.print(new String(buffer,0,length));
                count++ ;
            }
            System.out.println("\n一共读取了"+count+"次");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(reader!=null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
